using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using RAG.Application.Services.Interfaces;
using RAG.Application.Services.Implementations;
using RAG.Application.Services;
using RAG.Application.Events.Handlers;
using MediatR;
using System.Reflection;

namespace RAG.Application;

public static class ServiceCollectionExtension
{
    public static IServiceCollection AddApplicationServices(this IServiceCollection services, IConfiguration configuration)
    {
        // 注册MediatR
        services.AddMediatR(Assembly.GetExecutingAssembly());

        // 注册应用层服务
        services.AddScoped<IAuthService, AuthService>();
        services.AddScoped<IUserService, UserService>();
        services.AddScoped<IPermissionService, PermissionService>();
        services.AddScoped<IRoleService, RoleService>();
        services.AddScoped<ISystemLogService, SystemLogService>();
        services.AddScoped<IDocumentApplicationService, DocumentApplicationService>();

        // 注册RAG相关服务
        services.AddScoped<IKnowledgeBaseService, KnowledgeBaseService>();
        services.AddScoped<IRagChatService, RagChatService>();
        services.AddScoped<IRagQuestionAnswerService, RagQuestionAnswerService>();
        services.AddScoped<IConversationService, ConversationService>();
        services.AddScoped<ISessionService, SessionService>();

        // 注册事件处理器
        services.AddScoped<UserEventHandlers>();

        return services;
    }
}
